from enum import Enum

class StatusEnum(Enum):
    PENDING = (1, "即将开始")
    INQUIRY_ACTIVE  = (2, "正在进行")
    BIDDING_CLOSED  = (3, "竞价结束")
    SUCCESS = (4, "已成交")
    ERROR = (5, "已流标")
    UNKNOWN = (-11, "未知状态")

    def __init__(self, code, display_name):
        self.code = code
        self.display_name = display_name

    @classmethod
    def _build_code_map(cls):
        """构建代码到枚举成员的映射字典"""
        # 仅在第一次访问时构建
        if not hasattr(cls, '_code_map'):
            cls._code_map = {member.code: member for member in cls}
        return cls._code_map

    @classmethod
    def get_display_name(cls, code):
        """根据状态码获取显示名称"""
        member = cls._build_code_map().get(code)
        return member.display_name if member else cls.UNKNOWN.display_name

    @classmethod
    def get_common_info(cls,code):
        member = cls._build_code_map().get(code)
        if member:
            return {"show_name": member.display_name,"status":member.code,"status_name":member.display_name}
        return {"show_name": cls.UNKNOWN.display_name,"status":cls.UNKNOWN.code,"status_name":cls.UNKNOWN.display_name}
    @classmethod
    def from_code(cls, code):
        """根据状态码获取枚举成员"""
        return cls._build_code_map().get(code, cls.UNKNOWN)





    @classmethod
    def  get_ztep_status_list(cls):
        """获取状态列表"""
        return [
            {"show_status": ["2"], "show_name": "预告中", "status": cls.PENDING},
            {"show_status": ["3"], "show_name": "竞价中", "status": cls.INQUIRY_ACTIVE},
            {"show_status": ["4","5"], "show_name": "待定标", "status": cls.BIDDING_CLOSED},
            {"show_status": ["12"], "show_name": "待确认", "status": cls.BIDDING_CLOSED},
            {"show_status": ["13"], "show_name": "签约中", "status": cls.BIDDING_CLOSED},
            {"show_status": ["6"], "show_name": "已成交", "status": cls.SUCCESS},
            {"show_status": ["7","8"], "show_name": "已流标", "status": cls.ERROR},
            {"show_status": ["9"], "show_name": "已结束", "status": cls.BIDDING_CLOSED},
            {"show_status": ["11"], "show_name": "已作废", "status": cls.BIDDING_CLOSED},
            {"show_status": ["-1"], "show_name": "未知", "status":  cls.UNKNOWN}

        ]

    @classmethod
    def get_ztep_statust_info(cls, show_status):
       return cls.get_info_by_show_status(show_status,cls.get_ztep_status_list())

    @classmethod


    def get_tjyz_status_list(cls):
        """获取状态列表"""
        return [
            {"show_status": "Publish", "show_name": "报名中", "status": cls.PENDING},
            {"show_status": "EnterClosed", "show_name": "预展中", "status": cls.PENDING},
            {"show_status": "Bidding", "show_name": "正在进行", "status":cls.INQUIRY_ACTIVE},
            {"show_status": "BiddingCompleted", "show_name": "已成交", "status": cls.SUCCESS},
            {"show_status": "BiddingEnded", "show_name": "等待拍卖师操作", "status": cls.PENDING},
            {"show_status": "WaitBid", "show_name": "评标中", "status": cls.BIDDING_CLOSED},
            {"show_status": "BiddingAborted", "show_name": "已流拍", "status": cls.ERROR},
            {"show_status": "UNKNOWN", "show_name": "未知", "status": cls.UNKNOWN}
        ]

    @classmethod
    def get_tjyz_status(cls, show_status):
        return cls.get_info_by_show_status(show_status, cls.get_tjyz_status_list())

    @classmethod
    def get_tjyl_status_list(cls):
        return [
                {"show_status": "00", "show_name": "暂存", "status": cls.PENDING},
                {"show_status": "01", "show_name": "审核中", "status":  cls.PENDING},
                {"show_status": "10", "show_name": "报名中", "status": cls.PENDING},
                {"show_status": "20", "show_name": "保证金", "status":  cls.PENDING},
                {"show_status": "30", "show_name": "竞价中", "status":  cls.PENDING},
                {"show_status": "40", "show_name": "待开标", "status": cls.INQUIRY_ACTIVE},
                {"show_status": "50", "show_name": "审核中", "status":  cls.INQUIRY_ACTIVE},
                {"show_status": "60", "show_name": "已成交", "status":  cls.INQUIRY_ACTIVE},
                {"show_status": "61", "show_name": "流标", "status":  cls.INQUIRY_ACTIVE},
                {"show_status": "62", "show_name": "线下", "status":  cls.INQUIRY_ACTIVE},
                {"show_status": "70", "show_name": "失效/作废", "status":  cls.INQUIRY_ACTIVE},
                {"show_status": "71", "show_name": "作废待确认", "status":  cls.INQUIRY_ACTIVE},
                {"show_status": "80", "show_name": "已删除", "status":  cls.INQUIRY_ACTIVE}
    ]

    @classmethod

    def get_tjyl_status_info(cls,show_status):
        return cls.get_info_by_show_status(show_status,cls.get_tjyl_status_list())

    @classmethod
    def get_info_by_show_status(cls, show_status,status_list):
        show_status=str(show_status)
        for item in status_list:
            if item["show_status"] == show_status or show_status in item["show_status"]:
                return {
                    "show_name": item["show_name"],
                    "status": item["status"].code,
                    "status_name":item["status"].display_name
                }
        return {"show_name":"未知","Staus":cls.UNKNOWN.code,"status_name":cls.UNKNOWN.display_name}

if __name__ == "__main__":
   res= StatusEnum.get_ztep_statust_info(show_status=7)
   print(res)